﻿using UnityEngine;
using System.Collections;

public class paddleController2 : MonoBehaviour {
	
	public float paddleSpeed = 25.0f;
	
	// Use this for initialization
	void Start () {

	}
	
	void Update () {
		transform.position = new Vector3(transform.position.x + Input.GetAxis ("Horizontal") * paddleSpeed * Time.deltaTime, transform.position.y, transform.position.z); 
 		transform.position = new Vector3(Mathf.Clamp( transform.position.x, -14, 14), transform.position.y, transform.position.z);
	}
	
	void OnCollisionEnter(Collision collision) 
	{ 
		var velo = collision.rigidbody.velocity.magnitude; 
		collision.rigidbody.velocity = new Vector3((collision.transform.position.x - transform.position.x)*8, collision.rigidbody.velocity.y, collision.rigidbody.velocity.z); 
		if (collision.rigidbody.velocity.magnitude < velo)
		{
			collision.rigidbody.velocity *= velo/collision.rigidbody.velocity.magnitude; 
		}
	}
}
